IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetWFResources]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetWFResources]

/****** Object:  StoredProcedure [dbo].[GetWFResources]    Script Date: 08/21/2009 11:02:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO


/************************************************************************************************
* Name:		GetWFResources                                                          
* Purpose:	This stored procedure gets the Workflow Resources for particular role.
*		
* PARAMETERS  
*	Name			Description
* -------------------------	-----------------------------
* @OrgId			Organization id 
* @WorkflowRole			Workflow specific role
* return Resource ID 
*
************************************************************************************************
*Call: GetWFResources 1, 'HROIntake'
************************************************************************************************/
create procedure [dbo].[GetWFResources]
(
	@OrganizationId int,
	@workflowRole varchar(50),
	@workflowType varchar(10) = null
)
as
begin
	SET NOCOUNT ON
	CREATE TABLE #Resources
	( 
		[ID] int,
		WorkflowRole Varchar (50),
		PersonID int,
		OrgID int
	) 

	if @workflowType = ''
		Set @workflowType = null

	insert into #Resources
	([ID], WorkflowRole,PersonID,OrgID)
	Exec GetWorkflowPerson @OrganizationId, @workflowRole, @workflowType

	Select 
		FwkDomainUserID ResourceID
	From
		AdmPerson 
	Where 
		ID in (Select personID from #Resources)
END


